﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UpdateData
{
    public static class ExeclHeaderChange
    {
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int[] GetHeaderValue(string value)
        {
            value = value.ToUpper();
            int[] res = new int[2];
            List<string> letter = new List<string> { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
            string itemValue = "";
            string itemValue2 = "";
            foreach (var item in value)
            {
                if (letter.Contains(item.ToString()))
                {
                    itemValue += item.ToString();
                }
                else
                {
                    itemValue2+= item.ToString();
                }
            }
            res[0] = ChangeHeader(itemValue)-1;
            res[1] = Convert.ToInt32(itemValue2)-1;
            return res;

        }

        /// <summary>
        /// 获取table表的数字
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static int ChangeHeader(string name)
        {
            name=name.ToUpper();
            List<string> letter = new List<string> { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
            int SumCount = letter.Count();
            int result = 0;
            for (int i = 0; i < name.Length; i++)
            {
                string temp = name[i].ToString();
                int value= letter.IndexOf(temp)+1;

                int v = value * int.Parse(Math.Pow(SumCount, (name.Length - i - 1)).ToString());
                result += v;
            }
            return result;
        }
    }
}
